import axios from "axios";
import { showToast } from "vant";

const request = axios.create({
  baseURL: "https://geek.itheima.net/v1_0/",
  timeout: 50000,
});

request.interceptors.request.use(
  (config) => {
    let token = undefined
    if(headlines?.getUserInfo) {
      token = headlines?.getUserInfo()?.token
    } else if(headlines?.getToken) {
      token = headlines?.getToken()
    }

    // showToast({
    //   message: "token:" + token,
    // })

    try {
      if (token) {
        config.headers.Authorization = `Bearer ${token}`;
      }
    } catch (e) {
      showToast({ message: "黑马头条SDK异常" });
    }
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);

export { request };
